package com.dai.chun.dao.action;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import com.dai.chun.dao.dao.EmployeeDao;
import com.dai.chun.dao.dao.PerformanceDao;
import com.dai.chun.dao.impl.DepartmentDaoImpl;
import com.dai.chun.dao.impl.EmployeeDaoImpl;
import com.dai.chun.dao.impl.PerformanceDaoImpl;
import com.dai.chun.dao.model.Department;
import com.dai.chun.dao.model.Employee;
import com.dai.chun.dao.model.Performance;
import com.dai.chun.util.PageSplitUtil;

public class PerformanceAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private PerformanceDao performanceDao;
	private Performance performance;
	private List<Performance> performanceList;
	private PageSplitUtil psu;
	private Department department;
	private Employee employee;
	
	
	public String addPerformance() throws IOException, SQLException{
		EmployeeDao employeeDao=new EmployeeDaoImpl();
		Employee employee=employeeDao.findEmployeeById(performance.getPerformance_emp_id());
		performance.setPerformance_emp_name(employee.getEmp_name());
		
		performanceDao=new PerformanceDaoImpl();
		performanceDao.save(performance);
		return "succeed";
	}
	//显示添加 页面
	public String showAddPerformance() throws IOException, SQLException{
		
		return "showAddPerformance";
	}
	public String listPerformance() throws IOException, SQLException{
		performanceDao=new PerformanceDaoImpl();
		if(psu==null){
			psu=new PageSplitUtil(1);
		}
		psu.comput();
		psu.computPageCount(performanceDao.findAllCount());
		performanceList=performanceDao.listPerformance(psu);
		return "listPerformance";
	}
	public String listPerformanceByDeptId() throws IOException, SQLException{
		performanceDao=new PerformanceDaoImpl();
		if(psu==null){
			psu=new PageSplitUtil(1);
		}
		psu.comput();
		psu.computPageCount(performanceDao.findAllCount());
		performanceList=performanceDao.listPerformanceByDeptId(psu,department.getDept_id());
		return "listByDeptIdPerformance";
	}
	
	//删除
	public String delPerformance() throws SQLException{
		performanceDao=new PerformanceDaoImpl();
		performanceDao.delPerformance(performance.getPerformance_id());
		return "succeed";
	}
	
	//修改
	public String updatePerformance() throws SQLException{
		performanceDao=new PerformanceDaoImpl();
		performanceDao.updatePerformance(performance);
		return "succeed";
	}
	//显示修改页面
	public String showUpdatePerformance() throws SQLException{
		performanceDao=new PerformanceDaoImpl();
		performance=performanceDao.findPerformanceById(performance.getPerformance_id());
		return "showUpdatePerformance";
	}
	
	
	public List<Performance> getPerformanceList() {
		return performanceList;
	}
	public void setPerformanceList(List<Performance> performanceList) {
		this.performanceList = performanceList;
	}
	
	public Performance getPerformance() {
		return performance;
	}
	public void setPerformance(Performance performance) {
		this.performance = performance;
	}

	public PageSplitUtil getPsu() {
		return psu;
	}

	public void setPsu(PageSplitUtil psu) {
		this.psu = psu;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}
	public Employee getEmployee() {
		return employee;
	}
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

}
